﻿
using System;
using System.Net;
using System.Net.Sockets;
using UnityEngine;

namespace QPEngine
{
    public static class Util
    {   
        /// <summary>
        /// 获取平台名字
        /// </summary>
        public static string PlatformName
        {
            get
            {
                string name = "UNKNOWN";
                switch (Application.platform)
                {
                    case RuntimePlatform.Android: name = AppConst.AndroidPlatformName; break;
                    case RuntimePlatform.IPhonePlayer: name = AppConst.iOSPlatformName; break;
                    case RuntimePlatform.WindowsPlayer: name = AppConst.WindowsPlatformName; break;
                    case RuntimePlatform.WindowsEditor: name = AppConst.WindowsPlatformName; break;
                    case RuntimePlatform.OSXPlayer: name = AppConst.iOSPlatformName; break;
                    case RuntimePlatform.OSXEditor: name = AppConst.iOSPlatformName; break;
                }
                return name;
            }
        }

        public static ushort PlatforType
        {
            get
            {
                ushort type = (ushort)DeviceType.UNKNOWN;
                switch (Application.platform)
                {
                    case RuntimePlatform.Android: type = (ushort)DeviceType.ANDROID; break;
                    case RuntimePlatform.IPhonePlayer: type = (ushort)DeviceType.iOS; break;
                    case RuntimePlatform.WindowsPlayer: type = (ushort)DeviceType.WIN; break;
                    case RuntimePlatform.WindowsEditor: type = (ushort)DeviceType.WINEDITOR; break;
                    case RuntimePlatform.OSXEditor: type = (ushort)DeviceType.MACEDITOR; break;
                    case RuntimePlatform.OSXPlayer: type = (ushort)DeviceType.MAC; break;
                }
                return type;

            }
        }

        public static string HostIP
        {
            get
            {
                string name = Dns.GetHostName();
                IPAddress[] ipadrlist = Dns.GetHostAddresses(name);
                foreach (IPAddress ipa in ipadrlist)
                {
                    if (ipa.AddressFamily == AddressFamily.InterNetwork)
                    {
                        name = ipa.ToString();
                    }
                }
                return name;
            }
        }

        /// <summary>
        /// 获取大厅版本（也可以说第几套皮肤）
        /// </summary>
        public static int SkinVersion
        {
            get
            {
                string version = Application.version;
                if (version.Contains("."))
                {
                    version = version.Split('.')[0];
                }
                else
                {
                    version = version.Substring(0, 1);
                }
                int v = -1;
                int.TryParse(version, out v);
                return v;
            }
        }
        /// <summary>
        /// 返回UpdateConfiger在服务器存放的目录结构
        /// </summary>
        public static string ServerUpdateConfigerPath
        {
            get
            {
                string path = string.Format("/{0}/{1}/{2}/{3}", AppConst.CdnDirectoryName, Util.PlatformName, AppConst.HotUpdateDirectoryName, AppConst.UpdateConfigerName);
                return path;
            }
        }

        /// <summary>
        /// 返回ValueConfiger在服务器存放的目录结构
        /// </summary>
        public static string ServerValueConfigerPath
        {
            get
            {
                string path = string.Format("/{0}/{1}/{2}/{3}", AppConst.CdnDirectoryName, Util.PlatformName, AppConst.GameAssetDirectoryName, AppConst.ValueConfigerName);
                return path;
            }
        }

        /// <summary>
        /// 返回AppInfoConfiger在服务器存放的目录结构
        /// </summary>
        public static string ServerAppInfoConfigerPath
        {
            get
            {
                string path = string.Format("/{0}/{1}", AppConst.CdnDirectoryName, AppConst.AppInfoConfigerName);
                return path;
            }
        }

        /// <summary>
        /// 返回GameEnterConfiger在服务器存放的目录结构
        /// </summary>
        public static string ServerGameEnterConfigerPath
        {
            get
            {
                string path = string.Format("/{0}/{1}", AppConst.CdnDirectoryName, AppConst.GameEnterConfigerName);
                return path;
            }
        }

    }
}
